<?php
/**
 * Created by PhpStorm.
 * User: yangchunrun
 * Date: 17/3/22
 * Time: 下午5:42
 */

if (!defined('IN_DISCUZ') || !defined('IN_WEIXINAPP')) {
    exit('Access Denied');
}


loadcache('plugin');
$splugin_setting = $_G['cache']['plugin']['thinker_wx'];


include DISCUZ_ROOT . './source/plugin/thinker_wx/wechat.class.php';
include DISCUZ_ROOT . './source/plugin/thinker_wx/response.class.php';


$wechat_client = new Wechat(array('appid' => $splugin_setting['wx_appid'], 'appsecret' => $splugin_setting['wx_appsecret'],'token'=>$splugin_setting['wx_token']));
$wechat_client->valid();

$receive = $wechat_client->getRev();
$receive = $wechat_client->getRevData();



if ($receive['MsgType'] == 'event' && $receive['Event'] == 'subscribe') {

    response::reply('subscribe','',$wechat_client);

}

$keyword = trim($receive['Content']);

if ($receive['MsgType'] == 'event' && $receive['Event'] == 'CLICK') {
    $keyword = trim($receive['EventKey']);
}

if (empty($keyword)) {
    $wechat_client->text('无效的指令')->reply();
}else{
    response::reply('keyword',$keyword,$wechat_client);
}




